﻿CREATE PROCEDURE [dbo].[proc_Assets_Getlist_ByUserId]
	(
		@CompanyId int,
		@CategoryId int,
		@NameId int,
		@StateId int,
		@StartIndex int,
		@EndIndex INT,
		@UserId VARCHAR(50)
	)
AS
	;WITH list as (Select ROW_NUMBER() OVER (ORDER BY a.Id)AS Row,
	a.Id,
	a.GId,
	a.CategoryId,
	(Select Title From Assets_Categorys Where Id=a.CategoryId) As CategoryName,
	NameId,
	(Select Title From Assets_Names Where Id=a.NameId) As NameTitle,
	Description,
	CompanyId,
	(Select CompanyName From Company Where Id=a.CompanyId) As CompanyName,	
	UserName,
	EName,
	StateId,
	(Select Title From Assets_States Where Id=a.StateId) As StateName,
	Prices,
	DJUserName,
	DJDate,
	GGXH,
	GZDate,
	IsNULL(IsApplyBf,0) AS IsApplyBf,
	ANumber,
	IsNull(LyDate,'1900-01-01') as LyDate
	From Assets a
	Where ( a.CompanyId=@CompanyId) AND a.UserName=@UserId and
	(@CategoryId=0 Or a.CategoryId=@CategoryId) and (@NameId=0 Or a.NameId=@NameId) and (@StateId=0 Or a.StateId=@StateId)
	 
	)
	
	Select * From list,(Select Count(Id) AS cid From list
	) AS n Where Row between @StartIndex and @EndIndex
	
	RETURN
